package com.xwtec.iterator.v4;

import java.util.LinkedList;

/**
 * @Author: zt
 * @Date: 2021/3/4 21:34
 */
public class Main {
}


class ArrayList_ implements Collection_ {

    Object[] objects = new Object[10];
    int index = 0;

    @Override
    public void add(Object o){
        if(index == objects.length){
            Object[] newObject = new Object[objects.length*2];
            System.arraycopy(objects,0,newObject,0,objects.length);
            objects = newObject;
        }
        objects[index]= o;
        index++;
    }

    @Override
    public int getSize(){
        return index;
    }

    @Override
    public Iterator_ iterator() {
        return null;
    }

}

class LinkedList_ implements Collection_ {
    Node head = null;
    Node tail = null;
    int size = 0;

    @Override
    public void add(Object o) {

        Node n = new Node(o);
        if (head == null) {
            head = n;
            tail = n;

        } else {
            tail.next = n;
            tail = n;

        }
        size++;

    }

    @Override
    public int getSize(){
        return size;
    }

    @Override
    public Iterator_ iterator() {
        return null;
    }

    private class LinkIterator implements Iterator_{

        private int currentIndex = 0;


        @Override
        public boolean hasNext() {
            if(currentIndex>=size) return false;
            return true;
        }

        @Override
        public Object next() {

            return null;
        }
    }

    //一个内部节点类
    private class Node {
        //节点类自己的数据
        Object o;
        //指向的下一个节点
        Node next;

        public Node(Object o) {
            this.o = o;
        }

    }
}

interface Collection_{
    void add(Object o);
    int getSize();
    Iterator_ iterator();
}

interface Iterator_{
    boolean hasNext();
    Object next();
}